<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
	<title>Controlling other Applications from MacPython</title>
	<meta name="generator" content="BBEdit 6.5.3">
	<link rel="SHORTCUT ICON" href="pythonsmall.gif">
	<META NAME="AppleIcon" CONTENT="pythonsmall.gif">
</head>
<body>
<h1>Controlling other Applications from MacPython</h1>

<p>Python has a fairly complete implementation of the Open Scripting
Architecure (OSA, also commonly referred to as AppleScript), allowing
you to control scriptable applications from your Python program,
and with a fairly pythonic interface. This piece of
Python:</p>
	
<blockquote><pre><tt>
import Finder

f = Finder.Finder()
print f.get(f.window(1).name)
</tt></pre></blockquote>

<p>is identical to the following piece of AppleScript:</p>

<blockquote><pre><tt>
tell application "Finder"
	get name of window 1
end tell
</tt></pre></blockquote>

<p>To send AppleEvents to an application you must first create the Python
modules interfacing to the terminology of the application (what
<tt>Script Editor</tt> calls the "Dictionary"). Use the IDE menu command
<tt>File-&gt;Generate OSA Suite...</tt> for this. For more control run</p>

<blockquote><tt>
pythonw .../Lib/plat-mac/gensuitemodule.py --help
</tt></blockquote>

<p>from a terminal window.</p>

<h2>Creating a scriptable application in Python</h2>

You can also create a scriptable application in Python, but this is not
very well documented. For Carbon
applications you should look at the <tt>MiniAEFrame</tt> module.

</body>
</html>
